package com.aabte.openfeignlearn.example.provider;

import com.aabte.openfeignlearn.example.interfaces.HelloService;
import com.aabte.openfeignlearn.example.interfaces.Person;
import com.aabte.openfeignlearn.example.interfaces.ResponseBean;
import com.aabte.openfeignlearn.example.interfaces.ServletUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Daniel
 */
@Slf4j
@RestController
public class ProviderHelloController implements HelloService {


    @Override
    public ResponseBean<Person> hello200() {
        Person tom = Person.builder().name("tom").age(18).build();
        return ResponseBean.<Person>builder().code("0").message("success").data(tom).build();
    }

    @Override
    public ResponseBean<Person> hello400() {
        ServletUtils.setStatus(400);
        return ResponseBean.<Person>builder().code("400").message("parameter error.").build();
    }

    @Override
    public ResponseBean<Person> hello404() {
        ServletUtils.setStatus(404);
        return ResponseBean.<Person>builder().code("404").message("resource not found.").build();
    }

    @Override
    public ResponseBean<Person> hello500() {
        ServletUtils.setStatus(500);
        return ResponseBean.<Person>builder().code("500").message("server error.").build();
    }
}
